#include "Utils.h"
#include "ListNode.h"
#include "TreeNode.h"
#include <iostream>
#include <vector>
#include <string>

using namespace std;

class Issue326 {
public:
	bool isPowerOfThree(int n) {
		if (n<=0)
			return false;
		while(0==n%3)
			n=n/3;
		return n==1;
	}

	/*This can be generalized for any prime number n.
	Lets say we have 2 number m & n.
	If m is a power of n then for any number p,
	1.  For all p<=m
	2.  m%p = 0 if and only if p is also a power of n
	We can use this concept here also. In this case n=3 and m is largest 32bit signed integer which is power of 3 i.e. 1162261467.*/
	bool isPowerOfThree2(int p) {
			return  p>0 && 1162261467%p == 0 ;
	}
};

int main326(){

	Issue326 sol;
	int n;
	while (true)
	{
		cin>>n;
		cout<<sol.isPowerOfThree(n)<<endl;
	}

	return 0;
}